#!/bin/bash
CROSS_PATH = arm-linux-gnueabihf-
#export CROSS_PATH=

OUTPUT_PATH = /home/qlqcetc/nfs
CFLAGS += -Wall -Wno-unused-local-typedefs
OUTPUT = out.elf
#LIBS = -lplat
LDFLAGS = -L lib  -lpthread -lmad -lid3tag -lasound -lmp3lame

##################################################################################

#arch
SRCS += $(wildcard ../src/plat/v3s/*.c)
CFLAGS += -I ../src/plat/
#CFLAGS += -I /usr/local/lib/mad_x86/include/
CFLAGS += -I /opt/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/
SDIR = ../src
#add src
SRCS += $(wildcard $(SDIR)/*.c)
SRCS += $(wildcard ../src/sys/*.c)
SRCS += $(wildcard ../src/share/*.c)
SRCS += $(wildcard ../src/board/*.c)
SRCS += $(wildcard ../src/http/*.c)
SRCS += $(wildcard ../src/http/web/*.c)
SRCS += $(wildcard ../src/ipadp/*.c)
SRCS += $(wildcard ../src/iprec/*.c)
SRCS += $(wildcard ../src/mp3encode/*.c)

#add inc
CFLAGS += -I ../src/
CFLAGS += -I ../src/sys/
CFLAGS += -I ../src/share/
CFLAGS += -I ../src/board/
CFLAGS += -I ../src/board/plat/
CFLAGS += -I ../src/http/
CFLAGS += -I ../src/http/web/
CFLAGS += -I ../src/ipadp/
CFLAGS += -I ../src/iprec/
CFLAGS += -I ../src/mp3encode/



##################################################################################

CC = $(CROSS_PATH)gcc
AR = $(CROSS_PATH)ar

OBJS=$(addprefix obj/, $(addsuffix .o, $(basename $(notdir $(SRCS)))))


all : deps $(OUTPUT) run 

.PHONY+= deps
deps: 
	@for f in $(SRCS); do \
		OBJ=obj/`basename $$f|sed -e 's/\.cpp/\.o/' -e 's/\.cxx/\.o/' -e 's/\.cc/\.o/' -e 's/\.c/\.o/'`; \
		echo $$OBJ: $$f>> deps; \
		echo '	@echo -e "compiling $(CC) ": ' $$f >> deps; \
		echo '	@$(CC) $$(CFLAGS) -c -o $$@ $$^'>> deps; \
	done
	@echo "deps creat"
-include ./deps

.PHONY += $(OUTPUT)
$(OUTPUT): $(OBJS)
	$(CC) $(DBG) $(CFLAGS) $^ $(LDFLAGS) -o $@ 

.PHONY += run
run :
	cp $(OUTPUT) $(OUTPUT_PATH)/.
	
.PHONY += clean	

	
clean: 
	@rm -rf obj/*.o deps $(OUTPUT)
	

